﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// 管理员信息表dao 的摘要说明
/// </summary>
public class 管理员信息表dao
{
	public 管理员信息表dao()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}


    #region  成员方法

    /// <summary>
    /// 是否存在该记录
    /// </summary>
    public bool Exists(string username)
    {
        StringBuilder strSql = new StringBuilder();
        strSql.Append("select count(1) from 管理员信息表");
        strSql.Append(" where username=@username ");
        SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.NVarChar,50)};
        parameters[0].Value = username;

        return DataBase.runExecuteScalar(strSql.ToString(), parameters)>=1;


    }


    /// <summary>
    /// 增加一条数据
    /// </summary>
    public int Add(管理员信息表 model)
    {
        StringBuilder strSql = new StringBuilder();
        strSql.Append("insert into 管理员信息表(");
        strSql.Append("username,password,degree,seed)");
        strSql.Append(" values (");
        strSql.Append("@username,@password,@degree,@seed)");
        SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.NVarChar,50),
					new SqlParameter("@password", SqlDbType.NVarChar,50),
					new SqlParameter("@degree", SqlDbType.NVarChar,50),
					new SqlParameter("@seed", SqlDbType.NVarChar,50)};
        parameters[0].Value = model.username;
        parameters[1].Value = model.password;
        parameters[2].Value = model.degree;
        parameters[3].Value = model.seed;
        return DataBase.runExecute(strSql.ToString(), parameters);
    }
    /// <summary>
    /// 更新一条数据
    /// </summary>
    public int Update(管理员信息表 model)
    {
        StringBuilder strSql = new StringBuilder();
        strSql.Append("update 管理员信息表 set ");
        strSql.Append("password=@password,");
        strSql.Append("degree=@degree,");
        strSql.Append("seed=@seed");
        strSql.Append(" where username=@username ");
        SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.NVarChar,50),
					new SqlParameter("@password", SqlDbType.NVarChar,50),
					new SqlParameter("@degree", SqlDbType.NVarChar,50),
					new SqlParameter("@seed", SqlDbType.NVarChar,50)};
        parameters[0].Value = model.username;
        parameters[1].Value = model.password;
        parameters[2].Value = model.degree;
        parameters[3].Value = model.seed;

        return DataBase.runExecute(strSql.ToString(), parameters);
    }

    /// <summary>
    /// 删除一条数据
    /// </summary>
    public int Delete(string username)
    {

        StringBuilder strSql = new StringBuilder();
        strSql.Append("delete from 管理员信息表 ");
        strSql.Append(" where username=@username ");
        SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.NVarChar,50)};
        parameters[0].Value = username;

        return DataBase.runExecute(strSql.ToString(), parameters);
    }


    /// <summary>
    /// 得到一个对象实体
    /// </summary>
    public 管理员信息表 GetModel(string username)
    {

        StringBuilder strSql = new StringBuilder();
        strSql.Append("select  top 1 username,password,degree,seed from 管理员信息表 ");
        strSql.Append(" where username=@username ");
        SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.NVarChar,50)};
        parameters[0].Value = username;

        管理员信息表 model = new 管理员信息表();

        //DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

        DataSet ds = DataBase.runProcGetSet(strSql.ToString(), parameters);

        if (ds.Tables[0].Rows.Count > 0)
        {
            model.username = ds.Tables[0].Rows[0]["username"].ToString();
            model.password = ds.Tables[0].Rows[0]["password"].ToString();
            model.degree = ds.Tables[0].Rows[0]["degree"].ToString();
            model.seed = ds.Tables[0].Rows[0]["seed"].ToString();
            return model;
        }
        else
        {
            return null;
        }
    }

    /// <summary>
    /// 获得数据列表
    /// </summary>
    public DataSet GetList(string strWhere)
    {
        StringBuilder strSql = new StringBuilder();
        strSql.Append("select username,password,degree,seed ");
        strSql.Append(" FROM 管理员信息表 ");
        if (strWhere.Trim() != "")
        {
            strSql.Append(" where " + strWhere);
        }
        //return DbHelperSQL.Query(strSql.ToString());
        return DataBase.runProcGetSet(strSql.ToString());
    }

    /// <summary>
    /// 获得前几行数据
    /// </summary>
    public DataSet GetList(int Top, string strWhere, string filedOrder)
    {
        StringBuilder strSql = new StringBuilder();
        strSql.Append("select ");
        if (Top > 0)
        {
            strSql.Append(" top " + Top.ToString());
        }
        strSql.Append(" username,password,degree,seed ");
        strSql.Append(" FROM 管理员信息表 ");
        if (strWhere.Trim() != "")
        {
            strSql.Append(" where " + strWhere);
        }
        strSql.Append(" order by " + filedOrder);
        //return DbHelperSQL.Query(strSql.ToString());
        return DataBase.runProcGetSet(strSql.ToString());
    }

    /*
    /// <summary>
    /// 分页获取数据列表
    /// </summary>
    public DataSet GetList(int PageSize,int PageIndex,string strWhere)
    {
        SqlParameter[] parameters = {
                new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                new SqlParameter("@PageSize", SqlDbType.Int),
                new SqlParameter("@PageIndex", SqlDbType.Int),
                new SqlParameter("@IsReCount", SqlDbType.Bit),
                new SqlParameter("@OrderType", SqlDbType.Bit),
                new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                };
        parameters[0].Value = "管理员信息表";
        parameters[1].Value = "ID";
        parameters[2].Value = PageSize;
        parameters[3].Value = PageIndex;
        parameters[4].Value = 0;
        parameters[5].Value = 0;
        parameters[6].Value = strWhere;	
        return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
    }*/

    #endregion  成员方法
}
